package com.wingsboat;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @author wangzhong
 * @description: TODO
 * @date 2024/7/20 19:49
 */
public class Test8 {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        List<Integer> list = new LinkedList<>();
        int count = 0;
        for(int i=0;i<str.length();i++){
            char c= str.charAt(i);
            if(c=='(') list.add(1);
            if(c == ')') {
                if(list.size()>0){
                    count = count + 1;
                    list.remove(list.size()-1);
                }else{
                    count=-1;
                    break;
                }
            }
        }
        System.out.println(list.size()>0?-1:count);
    }
}
